export let home = {
    namespaced: true,
    state: {
        holidayData: null,
        setHoliday: null,
        reset: null,
        weekData: null,
        principalData: null,
        timeRuleData: null,
        submiTimeRule: null,
    },
    actions: {
        PostSubmiTimeRule(store, data = {}) {
            let url = "/week";
            return new Promise((resolve, reject) => {
                axios.post(url, data).then(({
                    data
                }) => {
                    store.commit('setSubmiTimeRule', data);
                    resolve(data);
                }).catch((error) => {
                    if (error.response) {
                        // 请求已发出，但服务器响应的状态码不在 2xx 范围内
                        reject(error.response.data)
                    }
                });
            });
        },
        GetTimeRuleData(store, data = {}) {
            let url = "/week";
            return new Promise((resolve, reject) => {
                axios.get(url, {
                    params: data
                }).then(({
                    data
                }) => {
                    store.commit('setTimeRuleData', data);
                    resolve(data);
                }).catch((error) => {
                    if (error.response) {
                        // 请求已发出，但服务器响应的状态码不在 2xx 范围内
                        reject(error.response.data)
                    }
                });
            });
        },
        GetPrincipalData(store, data = {}) {
            let url = "/school-info";
            return new Promise((resolve, reject) => {
                axios.get(url, {
                    params: data
                }).then(({
                    data
                }) => {
                    store.commit('setPrincipalData', data);
                    resolve(data);
                }).catch((error) => {
                    if (error.response) {
                        // 请求已发出，但服务器响应的状态码不在 2xx 范围内
                        reject(error.response.data)
                    }
                });
            });
        },
        GetWeekData(store, data = {}) {
            let url = "/week";
            return new Promise((resolve, reject) => {
                axios.get(url, {
                    params: data
                }).then(({
                    data
                }) => {
                    store.commit('setWeekData', data);
                    resolve(data);
                }).catch((error) => {
                    if (error.response) {
                        // 请求已发出，但服务器响应的状态码不在 2xx 范围内
                        reject(error.response.data)
                    }
                });
            });
        },
        DeleteReset(store, data = {}) {
            let url = "/holiday/cleanup";
            return new Promise((resolve, reject) => {
                axios.delete(url, {
                    data,
                }).then(({
                    data
                }) => {
                    store.commit('setReset', data);
                    resolve(data);
                }).catch((error) => {
                    if (error.response) {
                        // 请求已发出，但服务器响应的状态码不在 2xx 范围内
                        reject(error.response.data)
                    }
                });
            });
        },
        PostSetHoliday(store, data = {}) {
            let url = "/holiday";
            return new Promise((resolve, reject) => {
                axios.post(url, data).then(({
                    data
                }) => {
                    store.commit('setSetHoliday', data);
                    resolve(data);
                }).catch((error) => {
                    if (error.response) {
                        // 请求已发出，但服务器响应的状态码不在 2xx 范围内
                        reject(error.response.data)
                    }
                });
            });
        },
        GetHolidayData(store, data = {}) {
            let url = "/holiday";
            return new Promise((resolve, reject) => {
                axios.get(url, {
                    params: data
                }).then(({
                    data
                }) => {
                    store.commit('setHolidayData', data);
                    resolve(data);
                }).catch((error) => {
                    if (error.response) {
                        // 请求已发出，但服务器响应的状态码不在 2xx 范围内
                        reject(error.response.data)
                    }
                });
            });
        }
    },
    mutations: {
        setSubmiTimeRule(state, data = {}) {
            state.submiTimeRule = data;
        },
        setTimeRuleData(state, data = {}) {
            state.timeRuleData = data;
        },
        setPrincipalData(state, data = {}) {
            state.principalData = data;
        },
        setWeekData(state, data = {}) {
            state.weekData = data;
        },
        setReset(state, data = {}) {
            state.reset = data;
        },
        setSetHoliday(state, data = {}) {
            state.setHoliday = data;
        },
        setHolidayData(state, data = {}) {
            state.holidayData = data;
        }
    }
}